package com.csi.bumblebee.controller;

import com.csi.bumblebee.domain.dictionary.JobType;
import com.csi.bumblebee.domain.util.MyResult;
import com.csi.bumblebee.domain.util.StateCode;
import com.csi.bumblebee.service.JobTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.csi.bumblebee.domain.util.StateCode.FIND_FAILURE;
import static com.csi.bumblebee.domain.util.StateCode.FIND_SUCCESS;

/**
 * @author HUOJT
 */
@RestController
@RequestMapping("jobtype")
public class JobTypeController {


    @Autowired
    private JobTypeService jobTypeService;

    /**
     * 生成题目
     *
     * @param id 岗位类型id
     * @return 得到携带题目列表的岗位类型
     */
    @GetMapping("paper/{id}")
    public MyResult<JobType> makePaper(@PathVariable("id") String id) {
        MyResult<JobType> myResult = new MyResult<>(FIND_FAILURE, "查询题目数据失败");
        JobType jobType = jobTypeService.makePaper(id);
        if (jobType != null) {
            myResult.setCode(FIND_SUCCESS);
            myResult.setMessage("查询题目数据成功");
            myResult.setData(jobType);
        }
        return myResult;
    }

    /**
     * 查询所有三级岗位类型
     * @return List<JobType>
     */
    @GetMapping("/third")
    public MyResult<List<JobType>> listThird(){

        MyResult<List<JobType>> myResult = new MyResult<>();

        List<JobType> jobTypeList = jobTypeService.listThird();
        if (jobTypeList != null){
            myResult.setData(jobTypeList);
            myResult.setMessage("查询成功");
            myResult.setCode(StateCode.FIND_SUCCESS);
        }else {
            myResult.setCode(StateCode.FIND_FAILURE);
            myResult.setMessage("查询失败");
        }
        return myResult;
    }

    /**
     * 查询所有二级岗位分类
     */
    @GetMapping
    public MyResult<List<JobType>> listJobTypeTwo(){

        List<JobType> jobTypes = this.jobTypeService.listJobTypeTwo();

        if (jobTypes!=null && jobTypes.size()>0){
            return new MyResult<>(jobTypes, FIND_SUCCESS,"查询二级岗位分类成功");
        }
        return new MyResult<>(null, FIND_FAILURE,"查询二级岗位分类失败");
    }

    /**
     * 查询所有二级岗位分类
     */
    @GetMapping("/father")
    public MyResult<List<JobType>> listJobFather(){

        List<JobType> jobTypes = this.jobTypeService.listJobFather();

        if (jobTypes!=null && jobTypes.size()>0){
            return new MyResult<>(jobTypes, FIND_SUCCESS,"查询一级岗位分类成功");
        }
        return new MyResult<>(null, FIND_FAILURE,"查询一级岗位分类失败");
    }

    /**
     * 查询所有岗位分类
     */
    @GetMapping("/list/tree")
    public MyResult<List<JobType>> listJobTypeTree(){

        List<JobType> jobTypeList = this.jobTypeService.listJobTypeTree();

        if (jobTypeList!=null && jobTypeList.size()>0){
            return new MyResult<>(jobTypeList, FIND_SUCCESS,"查询所有岗位分类成功");
        }
        return new MyResult<>(null, FIND_FAILURE,"查询所有岗位分类失败");
    }

}
